package com.chenjunlin.app.common.convention.exception;

import com.chenjunlin.app.common.convention.errorcode.IErrorCode;
import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * 抽象项目中三类异常体系，客户端异常、服务端异常以及远程服务调用异常
 *
 * @see ClientException
 * @see ServiceException
 * @see RemoteException
 */
@Getter
public abstract class AbstractException extends RuntimeException {

    public final String errorCode;

    public final String errorMessage;

    public AbstractException(String message, Throwable throwable, IErrorCode errorCode) {
        super(message, throwable);
        this.errorCode = errorCode.code();
        if (StringUtils.hasText(message)) {
            this.errorMessage = message;
        } else if (StringUtils.hasText(errorCode.message())) {
            this.errorMessage = errorCode.message();
        } else {
            this.errorMessage = "未知错误";
        }
    }
}